import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { list as deviceTypeList } from '../deviceType/deviceType.api';
import { getDeviceModelByType } from '../deviceModel/deviceModel.api';
import { rules } from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
import { buildUUID } from '/@/utils/uuid';
import { JCronValidator } from '/@/components/Form';

export const columns: BasicColumn[] = [
  {
    title: '任务名称',
    dataIndex: 'name',
    width: 120,
  },
  {
    title: '任务调度',
    dataIndex: 'cron',
    width: 100,
  },
  {
    title: '启动/停止时间',
    dataIndex: 'updateTime',
    width: 120,
  },
  {
    title: '采集任务说明',
    dataIndex: 'remark',
    width: 80,
  },
  {
    title: '失败原因',
    dataIndex: 'reason',
    width: 100,
  },
  {
    title: '创建时间',
    dataIndex: 'createTime',
    width: 100,
  },
  {
    title: '任务状态',
    dataIndex: 'status',
    width: 100,
    fixed: 'right',
    customRender: ({ text }) => {
      return render.renderDict(text, 'iot_collect_status');
    },
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    label: '任务名称',
    field: 'name',
    component: 'Input',
    colProps: { span: 6 },
  },
  {
    label: '任务状态',
    field: 'status',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'iot_collect_status',
      placeholder: '请选择采集任务状态',
      stringToNumber: true,
    },
    colProps: { span: 6 },
  },
];

export const formSchema: FormSchema[] = [
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
  {
    label: '任务名称',
    field: 'name',
    component: 'Input',
    required: true,
  },
  {
    label: '调度',
    field: 'cron',
    component: 'JEasyCron',
    defaultValue: '* * * * * ? *',
    rules: [{ required: true, message: '请输入Cron表达式' }, { validator: JCronValidator }],
    required: true,
  },
  {
    label: '任务说明',
    field: 'remark',
    component: 'Input',
    required: true,
  },
];

export const debugColumns: BasicColumn[] = [
  {
    title: '名称',
    dataIndex: 'name',
    width: 120,
  },
  {
    title: '设备地址',
    dataIndex: 'childSn',
    width: 60,
  },
  {
    title: '数据格式',
    dataIndex: 'dataFormat',
    width: 60,
  },
  {
    title: '指令',
    dataIndex: 'cmd',
    width: 60,
    slots: { customRender: 'cmd' },
  },
  {
    title: '值类型',
    dataIndex: 'type',
    width: 80,
    slots: { customRender: 'type' },
  },
  {
    title: '起始地址',
    dataIndex: 'start',
    width: 60,
    slots: { customRender: 'start' },
  },
  {
    title: '自定义报文',
    dataIndex: 'message',
    width: 160,
    slots: { customRender: 'message' },
  },
];


export const searchDebugFormSchema: FormSchema[] = [
  {
    label: 'DTU名称',
    field: 'name',
    component: 'Input',
    colProps: { span: 6 },
  },
  {
    label: 'DTU编号',
    field: 'childSn',
    component: 'Input',
    colProps: { span: 6 },
  },
];

export const ProtocolType = [
  {label: '自定义', value: "cus"},
  {label: 'modbus:rtu', value: "rtu"},
  {label: 'modbus:tcp', value: "tcp"},
]

export const CmdOptions = [
  {label: '读01', value: "01"},
  {label: '读02', value: "02"},
  {label: '读03', value: "03"},
  {label: '读04', value: "04"},
  {label: '写05', value: "05"},
  {label: '写06', value: "06"},
  {label: '写10', value: "10"},
  {label: '写0F', value: "0F"},
];

export const TypeOptions = [
  {label: 'int', value: 'int'},
  {label: 'short', value: 'short'},
  {label: 'long', value: 'long'},
  {label: 'float', value: 'float'},
  {label: 'double', value: 'double'},
  {label: 'string', value: 'string'},
  {label: 'boolean', value: 'boolean'},
]

export const CmdCusOptions = [
  {label: '读', value: "read"},
  {label: '写(设备会响应)', value: "write"},
  {label: '异步写(设备不会响应)', value: "writeOfAsync"},
]